#ifndef __OPENLIST_H__
#define __OPENLIST_H__

/*
 *  OpenList.h
 *  OpenList class for search algorithms that use open list.
 *
 *  Gudmundur Mar Einarsson,
 *  Gylfi Gudmundsson,
 *  Hlynur Tryggvason
 *  Last modified: 13.02.2006
 */
#pragma once

#include <map>
#include <list>
#include <hash_map>
#include "State.h"
using namespace std;

class OpenState
{
public:
	StateID	 id;
	GWAction fromAction;
	Cost cost;
	Cost heuristic;
};

// Used to hold cost and heuristic seperately.
class CostPlusHeuristic
{
public:
	CostPlusHeuristic(Cost firstIn, Cost secondIn)
	{
		first = firstIn;
		second = secondIn;
	}
	Cost first;
	Cost second;

	bool operator <(const CostPlusHeuristic toCompare) const
	{
		if(this->first+this->second < toCompare.first+toCompare.second)
		{
			return true;
		}
		else if(this->first+this->second > toCompare.first+toCompare.second)
		{
			return false;
		}
		else
		{
			if(this->first < toCompare.first)
			{
				return true;
			}
			else if(this->first > toCompare.first)
			{
				return false;
			}
			else
			{
				return false;
			}
		}

	}
};


class OpenList
{
public:
	OpenList(void);
	~OpenList(void);
	OpenState* getByStateID(const StateID& stateID);
	void add(Cost shortFirst, Cost shortSecond, OpenState* openState);
	void remove(const StateID& stateID);
	bool empty();
	void clear();
	OpenState* getLowestCost();

private:
	map<StateID, OpenState*> m_mapID;
	multimap<CostPlusHeuristic, OpenState*> m_mapCost;	
};

#endif // __OPENLIST_H__